package com.tanhua.server.controller;

import com.tanhua.model.mongo.Movement;
import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.MovementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("movements")
public class MovementController {

    @Autowired
    private MovementService movementService;

    /**
     * 发布动态
     *
     * @param movement
     * @param imageContent
     * @return
     */
    @PostMapping
    public ResponseEntity movements(Movement movement, MultipartFile[] imageContent) throws IOException {
        movementService.publishMovement(movement, imageContent);
        return ResponseEntity.ok(null);
    }


    /**
     * 查询我的动态
     *
     * @param userId
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/all")
    public ResponseEntity<PageResult> findById(Long userId,
                                               @RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10") Integer pagesize) {

        PageResult pr = movementService.findById(userId, page, pagesize);
        return ResponseEntity.ok(pr);
    }


    /**
     * 查询好友动态
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/movements")
    public ResponseEntity<PageResult> findFriendMovements(@RequestParam(defaultValue = "1") Integer page,
                                                          @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = movementService.findFridenMovements(page, pagesize);
        return ResponseEntity.ok(pr);
    }
}
